package com.drakulo.hi.logic.actors;

import java.util.HashMap;
import java.util.Map;

import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import com.dk.hi.core.actor.Attribute;
import com.dk.hi.core.actor.Job;
import com.dk.hi.core.actor.Lineament;
import com.drakulo.hi.gfx.Face;
import com.drakulo.hi.gfx.Gauge;
import com.drakulo.hi.gfx.Item;
import com.drakulo.hi.logic.inventory.Inventory;
import com.drakulo.hi.logic.inventory.equipment.Equipment;
import com.drakulo.hi.logic.inventory.equipment.EquipmentType;

/**
 * Représente un héros de l'équipe
 */
public class Hero extends SomethingLiving {
	/**
	 * Son portrait
	 */
	private Face face;

	/**
	 * Jauge de points de sorts du héros
	 */
	private Gauge spellGauge;

	/**
	 * Jauge de poitns de vie du héros
	 */
	private Gauge lifeGauge;

	/**
	 * Classe du héros
	 */
	private Job job;

	/**
	 * Equipement actuel
	 */
	private Map<EquipmentType, Equipment> equipments;

	/**
	 * Inventaire du héros
	 */
	private Inventory inventory;

	public Hero(String name, Face face, Job job) {
		super(name);
		// setLineaments(new HashMap<Lineament, Integer>());
		// setAttributes(new HashMap<Attribute, Integer>());
		setJob(job);
		setFace(face);
		setEquipments(new HashMap<EquipmentType, Equipment>());
		setInventory(new Inventory());
		setSpellGauge(new Gauge(Color.blue));
		setLifeGauge(new Gauge(Color.red));

		updateLifeGauge();
		updateSpellGauge();
	}

	public Hero(String p_name, Map<Lineament, Integer> p_lineaments, Map<Attribute, Integer> p_attributes, Face p_face, Job job) {
		super(p_name);
		// setLineaments(p_lineaments);
		// setAttributes(p_attributes);
		setJob(job);
		setFace(p_face);
		setSpellGauge(new Gauge(Color.blue));
		setLifeGauge(new Gauge(Color.red));
		setEquipments(new HashMap<EquipmentType, Equipment>());

		updateLifeGauge();
		updateSpellGauge();
	}

	public void addItemToInventory(Item i, int ci, int ri) {
		this.inventory.put(ci, ri, i);
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Hero) || o == null) {
			return false;
		}
		Hero h = (Hero) o;
		if (h.getName().equals(getName())) {
			return true;
		}
		return false;
	}

	public Map<EquipmentType, Equipment> getEquipments() {
		return this.equipments;
	}

	public Image getFace() throws SlickException {
		return this.face.getImage();
	}

	public Inventory getInventory() {
		return this.inventory;
	}

	public Job getJob() {
		return this.job;
	}

	public Gauge getLifeGauge() {
		return this.lifeGauge;
	}

	public Gauge getSpellGauge() {
		return this.spellGauge;
	}

	public void setEquipments(Map<EquipmentType, Equipment> equipments) {
		this.equipments = equipments;
	}

	public void setFace(Face face) {
		this.face = face;
	}

	public void setInventory(Inventory inventory) {
		this.inventory = inventory;
	}

	public void setJob(Job job) {
		this.job = job;
	}

	public void setLifeGauge(Gauge lifeGauge) {
		this.lifeGauge = lifeGauge;
	}

	public void setSpellGauge(Gauge spellGauge) {
		this.spellGauge = spellGauge;
	}

	private void updateLifeGauge() {
		// this.lifeGauge.setMaxValue(getAttribute(Attribute.LIFE_PTS_MAX));
		// this.lifeGauge.setCurrentValue(getAttribute(Attribute.LIFE_PTS_CURRENT));

	}

	private void updateSpellGauge() {
		// this.spellGauge.setMaxValue(getAttribute(Attribute.SPELL_PTS_MAX));
		// this.spellGauge.setCurrentValue(getAttribute(Attribute.SPELL_PTS_CURRENT));
	}

	public Equipment wearEquipment(Equipment e, EquipmentType type) {
		Equipment last = this.equipments.get(type);
		this.equipments.put(type, e);
		return last;
	}
}
